
import java.util.Collection;
import java.util.HashMap;

/**
 * Singleton Factory for Students
 * 
 * Container and Administrator-Class for Students
 * 
 * 
 * @author Fleischhacker
 *
 */
public enum StudentFactory {
	INSTANCE;

	/**
	 * Pool for the Students
	 */
	private HashMap<Integer,Student> students = new HashMap<Integer,Student>();
	
	/**
	 * Returns the Student with the given MatrikelNr.
	 * If the MatNr is not found then a null value will be returned instead.
	 * @param _targetMatNr 
	 * @return Student if MatNr found, else Null
	 */
	public Student getStudentByMatrikelNr(int _targetMatNr){
		if(students.containsKey(_targetMatNr))
			return students.get(_targetMatNr);
		return null;
	}
	
	/**
	 * Adds a new Student to the Pool
	 * 
	 * edited by claab
	 * @param _matNr the matNr of the Student, unique
	 * @param _name  the Name of the Student
	 * @return success of adding the new Student with the given matNr
	 */
	public Student addNewStudent(int _matNr, String _name){
		if(students.containsKey(_matNr)) {
			return null;
		}
		Student s = new Student(_matNr,_name);
		students.put(_matNr, s);
		return s;
	}
	
	/**
	 * Returns a Collection of the studentpool
	 * If there are no Students it returns null instead
	 * @return collection full of students or null (if empty)
	 */
	public Collection<Student> getAllStudents(){
		if(students.isEmpty())
			return null;
		return students.values();
	}
}
